package com.ling.pl.security.view.url;

import com.bstek.dorado.annotation.DataProvider;
import com.bstek.dorado.annotation.DataResolver;
import com.bstek.dorado.annotation.Expose;
import com.ling.core.common.utils.D7PageUtils;
import com.ling.pl.security.feign.DefaultUrlService;
import com.ling.pl.security.model.DefaultUrlVO;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.Collection;

/**
 * @author bo.wang
 * @since 2013-2-3
 */
@Component("ling2.urlMaintain")
public class UrlMaintain {
    @Resource
    DefaultUrlService urlService;

    @Expose
    public void refreshUrlCache() {
        urlService.refreshUrlCache();
    }

    @DataProvider
    public Collection<DefaultUrlVO> loadUrls(String parentId) throws Exception {
        Collection<DefaultUrlVO> result = urlService.loadUrls(parentId);
        return result;
    }

    @DataResolver
    public void saveUrls(Collection<DefaultUrlVO> urls) throws Exception {
        urlService.saveMap(D7PageUtils.assembleDatasetMap(urls));
    }

    @Expose
    public int countChildren(String parentId) {
        return urlService.countChildren(parentId);
    }
}
